package org.example.www;

import java.rmi.RemoteException;

import org.apache.axis2.AxisFault;
import org.example.ws.FacadeStub;
import org.example.ws.FacadeStub.GetAllRestaurantData;
import org.example.ws.FacadeStub.GetAllRestaurantDataResponse;
import org.example.ws.FacadeStub.GetRestaurantInfoByCusine;
import org.example.ws.FacadeStub.GetRestaurantInfoByCusineResponse;
import org.example.ws.FacadeStub.GetRestaurantInfoByName;
import org.example.ws.FacadeStub.GetRestaurantInfoByRating;
import org.example.ws.FacadeStub.GetRestaurantInfoByRatingResponse;
import org.example.ws.FacadeStub.Restaurant;
import org.example.ws.FacadeStub.RestaurantList;
import org.example.ws.GetAllRestaurantDataFaultException;

import org.example.ws.FacadeStub.GetRestaurantInfoByNameResponse;
import org.example.ws.GetRestaurantInfoByCusineFaultException;
import org.example.ws.GetRestaurantInfoByNameFaultException;
import org.example.ws.GetRestaurantInfoByRatingFaultException;



public class FacadeWSClient
{
	private static final String SERVICE_END_POINT = "http://localhost:8080/axis2/services/Facade";	
	private FacadeStub stub;
	
	public FacadeWSClient()
	{
		try
		{
			stub = new FacadeStub(SERVICE_END_POINT);
		} catch (AxisFault e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	public org.example.ws.FacadeStub.EventsArray getAllEvents()
	{
		try
		{
			org.example.ws.FacadeStub.GetAllEventsResponse resu = new org.example.ws.FacadeStub.GetAllEventsResponse();
			org.example.ws.FacadeStub.GetAllEvents getAllRestaurantData = new org.example.ws.FacadeStub.GetAllEvents();
			getAllRestaurantData.setIn("");
			try
			{
				resu = stub.getAllEvents(getAllRestaurantData);
			}
			catch(RemoteException e)
			{
				System.out.println(e.getMessage());
			}
			catch(org.example.ws.GetAllEventsFaultException ex)
			{
				System.out.println(ex.getMessage());
			}
			return resu.getEventsArray();
		}
		catch(Exception e)
		{
			e.printStackTrace();
		}
		return null;
	}
	
	
	public RestaurantList getAllRestaurant()
	{
		try
		{
			GetAllRestaurantDataResponse resu = new GetAllRestaurantDataResponse();
			GetAllRestaurantData getAllRestaurantData = new GetAllRestaurantData();
			getAllRestaurantData.setIn("");
			try
			{
				resu = stub.getAllRestaurantData(getAllRestaurantData);
			}
			catch(RemoteException e)
			{
				System.out.println(e.getMessage());
			}
			catch(GetAllRestaurantDataFaultException ex)
			{
				System.out.println(ex.getMessage());
			}
			return resu.getOut();
		}
		catch(Exception e)
		{
			e.printStackTrace();
		}
		return null;
	}
	
	public Restaurant getRestaurantInfoByName(String name)
	{
		try
		{
			GetRestaurantInfoByName res = new GetRestaurantInfoByName();
			res.setIn("Acapulco");
			GetRestaurantInfoByNameResponse result = new GetRestaurantInfoByNameResponse();

			try
			{
				result = stub.getRestaurantInfoByName(res);
			}
			catch(RemoteException e)
			{
				System.out.println(e.getMessage());
			}
			catch(GetRestaurantInfoByNameFaultException ex)
			{
				System.out.println(ex.getMessage());
			}
			
			if(result.getOut() != null)
			{
				return result.getOut();
			}
		}
		catch(Exception e)
		{
			e.printStackTrace();
		}
		return null;
	}
	
	public RestaurantList getRestaurantInfoByCuisine(String cusine)
	{
		try
		{
			GetRestaurantInfoByCusine res = new GetRestaurantInfoByCusine();
			res.setIn(cusine);
			GetRestaurantInfoByCusineResponse result = new GetRestaurantInfoByCusineResponse();

			try
			{
				result = stub.getRestaurantInfoByCusine(res);
			}
			catch(RemoteException e)
			{
				System.out.println(e.getMessage());
			}
			catch(GetRestaurantInfoByCusineFaultException ex)
			{
				System.out.println(ex.getMessage());
			}
			
			if(result.getOut() != null)
			{
				return result.getOut();
			}
		}
		catch(Exception e)
		{
			e.printStackTrace();
		}
		return null;
	}

	public RestaurantList getRestaurantInfoByRating(double rating)
	{
		try
		{
			GetRestaurantInfoByRating res = new GetRestaurantInfoByRating();
			res.setIn(rating);
			GetRestaurantInfoByRatingResponse result = new GetRestaurantInfoByRatingResponse();

			try
			{
				result = stub.getRestaurantInfoByRating(res);
			}
			catch(RemoteException e)
			{
				System.out.println(e.getMessage());
			}
			catch(GetRestaurantInfoByRatingFaultException ex)
			{
				System.out.println(ex.getMessage());
			}
			
			if(result.getOut() != null)
			{
				return result.getOut();
			}
		}
		catch(Exception e)
		{
			e.printStackTrace();
		}
		return null;
	}
}
